package sort;

//选择排序
public class SelectSort {

	public static void main(String[] args) {
		int[] a = { 5, 2, 9, 3, 10, 1, 15, 2, 6, 7, 19, 50, 69, 100, 150, 160,
				132, 169 };
		for (int i : a) {
			System.out.print(i + " ");
		}
		sort(a);
	}

	public static void sort(int[] a) {
		System.out.println();
		for (int i = 0; i < a.length; i++) {
			int index = i; // 记录每次查找中最小值的索引
			for (int j = i + 1; j < a.length; j++) {
				if (a[j] < a[index]) {
					index = j;
				}
			}
			// 交换ai与最小值
			int temp = a[i];
			a[i] = a[index];
			a[index] = temp;
		}
		for (int i : a) {
			System.out.print(i + " ");
		}
	}
}
